#include <string>
#include <string.h>
#include <assert.h>
#include <iostream>

using namespace std;

#include "string_silulate.h"

void test_string1()
{
    qds::string s1("我的世界");
    cout << s1.c_str() << endl;
    qds::string s2("刘坤233");
    cout << s2.c_str() << endl;
    qds::string s3(s2);
    cout << s3.c_str() << endl;
    cout << s1.size() << " " << s3.size() << endl;
}

void test_string2()
{
    qds::string s1("liukun233!!!");
    qds::string s2("qingdiaoshenniubi!!!");
    qds::string s3(s1);

    cout << s1[1] << endl;
    s1[1] = 'o';
    cout << s1[1] << endl;
    s1 = s2;
    cout << s1.c_str() << endl;
    s1 = "xyz";
    cout << s1.c_str() << endl;
    s1 = 'b';
    cout << s1.c_str() << endl;
  
    const qds::string s4("nimavale!!!");
    const qds::string s5("hkt;!!!");
    s1[0] = 'x';
    s4[1];
    s5[1];
}

void test_string3()
{
    qds::string s1("cancanneed!");
    for (qds::string::iterator it = s1.begin(); it != s1.end(); ++it)
    {
        cout << *it;
    }
    cout << endl;

    for (qds::string::iterator it = s1.begin(); it != s1.end(); ++it)
    {
        (*it)++;
    }

    for (qds::string::iterator it = s1.begin(); it != s1.end(); ++it)
    {
        cout << *it;
    }
    cout << endl;

    //范围for其实底层就是迭代器,如果没有实现迭代器,那么就会报错
    for (auto e : s1)
    {
        cout << e;
    }
    cout << endl;
    //上面的范围for替换过后就是下面的代码
    //因为it使用自定义类型,所以改变迭代器的名称是不会影响下面的代码的
    //如果是改变begin或者是end的函数名,会影响下面的代码编译
    //for (auto it = s1.begin(); it != s1.end(); ++it)
    //{
    //    cout << *it;
    //}
    //cout << endl;
}

void test_string4()
{
    qds::string s1("Deep End");
    qds::string s2;
    qds::string s3("Miracle");
    qds::string s4("1111");

    cout << s1.c_str() << endl;
    s1.push_back('n');
    cout << s1.c_str() << endl;
    cout << s2.c_str() << endl;
    s2.push_back('x');
    cout << s2.c_str() << endl;
    
    cout << s1.c_str() << endl;
    s1.append("HOW MERRY MARRY");
    cout << s1.c_str() << endl;
    cout << s2.c_str() << endl;
    s2.append(s3);
    cout << s2.c_str() << endl;

    cout << s4.c_str() << endl;
    s4.append("2222222222222222222222222");
    cout << s4.c_str() << endl;
    
    //cout << s1.c_str() << endl;
    //s1 += "HOW MERRY MARRY";
    //cout << s1.c_str() << endl;
    //s2 += s3;
    //cout << s2.c_str() << endl;
    //s2 += 'x';
    //cout << s2.c_str() << endl;
}

void test_string5()
{
    qds::string s("Euphoria");
    cout << s.c_str() << endl;
    cout << "e:" <<s.find('e') << endl;
    cout << "E:" << s.find('E') << endl;
    cout << "ria:" << s.find("ria") << endl;
    cout << "music:" << s.find("music") << endl;
}

void test_string6()
{
    qds::string s1("1");
    cout << s1.c_str() << endl;
    s1.insert(0, "2345678");
    cout << s1.c_str() << endl;
    s1.insert(0, 'i');
    cout << s1.c_str() << endl;
    s1.erase(0, 2);
    cout << s1.c_str() << endl;

}
    
void test_string7()
{
    qds::string s1("abcde");
    qds::string s2("abcde");
    cout << (s1 == s2) << endl;
    qds::string s3("abcd");
    qds::string s4("abcde");
    cout << (s3 == s4) << endl;
    qds::string s5("abcde");
    qds::string s6("abcd");
    cout << (s5 == s6) << endl;
}

void test_string8()
{
    cout << endl;
    qds::string s1("abcde");
    cout << s1 << endl;
    cin >> s1;
    cout << s1 << endl;
}

int main()
{
    //test_string1();
    //test_string2();
    //test_string3();
    //test_string4();
    //test_string5();
    //test_string6();
    //test_string7();
    test_string8();
    return 0;
}
